package com.tiancheng.trade.merchant.controller.admin;

import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.commom.web.model.request.MerchantPayRegFileReqVO;
import com.tiancheng.trade.commom.web.model.response.MerchantPayRegFileResVO;
import com.tiancheng.trade.commom.web.model.response.MerchantRegAllInfoRes;
import com.tiancheng.trade.merchant.channel.IdPhotoEnums;
import com.tiancheng.trade.merchant.enums.MerchantTypeEnums;
import com.tiancheng.trade.merchant.exception.BusinessException;
import com.tiancheng.trade.merchant.model.Organization;
import com.tiancheng.trade.merchant.service.IMerchantPayRegService;
import com.tiancheng.trade.merchant.vo.merchant.*;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @Author: kellen
 * @Description: 商户进件 admin controller
 * @Date: create in 2024/11/19 15:17
 */
@RestController
@RequestMapping("/admin/merchantPayReg")
public class MerchantPayRegAdminController {

    @Resource
    private IMerchantPayRegService merchantPayRegService;

    /**
     * 分页查询组织机构信息
     *
     * @param queryMerchantRegReqVO {@link QueryMerchantRegReqVO}
     * @return {@link Result}<{@link PageInfo}<{@link QueryMerchantRegResVO}>>
     */
    @GetMapping("/findPageList")
    public Result<PageInfo<QueryMerchantRegResVO>> findPageList(QueryMerchantRegReqVO queryMerchantRegReqVO) throws BusinessException {
        return Result.success(merchantPayRegService.findPageList(queryMerchantRegReqVO));
    }

    /**
     * 手动设置银行商户进件信息
     *
     * @param req
     * @return
     * @throws IOException
     */
    @PostMapping("/manualSettingChannelInfo")
    public Result manualSettingChannelInfo(@RequestBody @Valid ManualSettingChannelInfoReq req){
        merchantPayRegService.manualSettingChannelInfo(req);
        return Result.success();
    }

    /**
     * 查询注册商户明细
     *
     * @return
     * @throws IOException
     */
    @GetMapping("/queryByRegId")
    public Result<MerchantRegAllInfoRes> queryRegisterMerchant(@RequestParam("regId") Long regId) throws IOException {
        //把文件的内容存储到本地磁盘上
        final MerchantRegAllInfoRes merchantPayRegResVOs = merchantPayRegService.queryRegisterMerchant(regId);
        return Result.success(merchantPayRegResVOs);
    }


    /**
     * 文件上传
     *
     * @param file
     * @return
     * @throws IOException
     */
    @PostMapping("/upload")
    public Result<MerchantPayRegFileResVO> upload(MultipartFile file) throws IOException {
        //把文件的内容存储到本地磁盘上
        //final MerchantPayRegFileResVO payRegFileResVO = merchantPayRegService.upload(file);
        //return Result.success(payRegFileResVO);
        return Result.success(new MerchantPayRegFileResVO());
    }

    /**
     * 证件照类型
     *
     * @return
     */
    @GetMapping("/idPhotoType")
    public Result<IdPhotoEnums[]> idPhotoType() {
        final IdPhotoEnums[] values = IdPhotoEnums.values();
        return Result.success(values);
    }

    /**
     * 商户类型
     *
     * @return
     */
    @GetMapping("/merchantType")
    public Result<MerchantTypeEnums[]> merchantType() {
        final MerchantTypeEnums[] values = MerchantTypeEnums.values();
        return Result.success(values);
    }

}
